package cn.udrm.water.base.v1.administration.repository;

import javax.validation.constraints.NotNull;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import cn.udrm.water.base.v1.administration.entities.AdministrationUnit;

@Repository
public interface AdministrationUnitRepository extends JpaRepository<AdministrationUnit, String>
			, JpaSpecificationExecutor<AdministrationUnit>{
	
	@EntityGraph(value="AdministrationUnit.all", type=EntityGraphType.FETCH)
	public Page<AdministrationUnit> findAll(@NotNull Specification<AdministrationUnit> specification, Pageable pageable);
	
	@Query(value="FROM AdministrationUnit w WHERE w.id=?1")
	@EntityGraph(value="AdministrationUnit.all", type=EntityGraphType.FETCH)
	public AdministrationUnit findAllById(String id);

}
